<%--
   zTree Selector
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@tag import="org.apache.commons.lang3.StringUtils"%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识."%>
<%@ attribute name="url" required="true" type="java.lang.String"
	description="默认显示的值。"%>
<%@ attribute name="name" type="java.lang.String" description="唯一标识."%>
<%@ attribute name="valueControlId" required="true"
	type="java.lang.String" description="值所保存的空间的Id。"%>

<%@ attribute name="valueColumn" required="false"
	type="java.lang.String" description="default id。"%>


<%@ attribute name="displayValue" required="true"
	type="java.lang.String" description="默认显示的值。"%>
<%@ attribute name="parentIdControlId" required="false"
	type="java.lang.String" description="parentIdControlId。"%>
<%@ attribute name="parentIdDesc" required="false"
	type="java.lang.String" description="parentIdDesc。"%>
	
	
<%@ attribute name="width" required="false" type="java.lang.Integer"
	description="对话框宽度，默认300"%>
<%@ attribute name="height" required="false" type="java.lang.Integer"
	description="对话框高度。默认300"%>
<%@ attribute name="displayValueCssClass" required="false"
	type="java.lang.String" description="displayValueCss样式名"%>
<%@ attribute name="displayValueCssStyle" required="false"
	type="java.lang.String" description="displayValueCssStyle样式名"%>
<%@ attribute name="afterSelected" required="false"
	type="java.lang.String" description="参数：(ids,names,treeNode)"%>
<%@ attribute name="displayColumn" required="false"
	type="java.lang.String" description="displayColumn"%>
<%@ attribute name="expandAllNode" required="false"
	type="java.lang.Boolean" description="expandAll"%>
<%@ attribute name="onlySelectLeaf" required="false"
	type="java.lang.Boolean" description="expandAll"%>
<%@ attribute name="asyncLoad" required="false" type="java.lang.Boolean"
	description="expandAll"%>
<%@ attribute name="autocompleteUrl" required="false"
	type="java.lang.String" description="autocompleteUrl"%>
<%@ attribute name="afterSelectEmpty" required="false"
	type="java.lang.String" description="afterSelectEmpty"%>
<%@ attribute name="treenodeCreateUrl" required="false"
	type="java.lang.String" description="afterSelectEmpty"%>
<c:set var="width" value="320" scope="request" />
<c:set var="height" value="360" scope="request" />
<c:set var="displayColumnName"
	value="${empty displayColumn?'treenodeNamePath':displayColumn}">
</c:set>
<c:set var="valueColumn"
	value="${empty valueColumn ? 'id' : valueColumn}">
</c:set>
<c:set var="asyncLoad" value="${empty asyncLoad ? true : asyncLoad}">
</c:set>
<c:set var="onlySelectLeaf"
	value="${empty onlySelectLeaf ? false : onlySelectLeaf}">
</c:set>
<%
	if (StringUtils.isEmpty(autocompleteUrl)) {
%>
<input id="${id}" name="${name}" type="text" value="${displayValue }"
	class="selector-input ${displayValueCssClass}"
	style="${displayValueCssStyle}" readonly="readonly"
	onclick="${id}Selector.openSelectDialog();return false;">

<div id="${id}Dialog" title="请选择"
	style="display:none;overflow: scroll;overflow-x:hidden;padding:0;">
	<div>
		<isperp:tree id="${id}Tree" cssStyle="width:${width-30 }px" 
			cusCreateUrl="${treenodeCreateUrl }" modal="readonly">
			<isperp:async enable="true" url="" type="" autoParam="'id'"
				otherParam="{asyncLoad:${asyncLoad }}"></isperp:async>
			<isperp:callback
				onDblClick="function(event, treeId, treeNode){${id}Selector.onNodeDblClick(event, treeId, treeNode);}"
				onAsyncSuccess="if('${expandAllNode }'){${id }Tree.expandAll();}"></isperp:callback>
			<isperp:view nameIsHTML="true" showTitle="false"></isperp:view>
			<c:if test="${not empty treenodeCreateUrl  }">
				<isperp:edit enable="true" showRemoveBtn="false"
					showRenameBtn="false"></isperp:edit>
				<isperp:view showTitle="false" addHoverDom="true"
					removeHoverDom="true"></isperp:view>
			</c:if>
		</isperp:tree>
	</div>
</div>
<%
	} else {
%>

<input id="${id}" name="${name}" type="text" value="${displayValue }"
	class=" ${displayValueCssClass}" style="${displayValueCssStyle}">

<a id="${id}Selector"
	class="selector-input  icon icon-search ${selectorCssClass }"
	style="display: inline;padding:1px 0px" href="javascript:void(0);"
	onclick="${id}Selector.openSelectDialog();"><span
	style="display:inline-block; text-indent:-999em;width:16px;height:16px">选择</span>
</a>
<div id="${id}Dialog" title="请选择"
	style="display:none;overflow: scroll;overflow-x:hidden;padding:0;">
	<div>
		<isperp:tree id="${id}Tree" cssStyle="width:${width-30 }px"
			cusCreateUrl="${treenodeCreateUrl }" modal="readonly">
			<isperp:async enable="true" url="" type="" autoParam="'id'"
				otherParam="{asyncLoad:${asyncLoad }}"></isperp:async>
			<isperp:callback
				onDblClick="function(event, treeId, treeNode){${id}Selector.onNodeDblClick(event, treeId, treeNode);}"></isperp:callback>

			<c:if test="${not empty treenodeCreateUrl  }">
				<isperp:edit enable="true" showRemoveBtn="false"
					showRenameBtn="false"></isperp:edit>
				<isperp:view showTitle="false" addHoverDom="true"
					removeHoverDom="true"></isperp:view>
			</c:if>
		</isperp:tree>
	</div>
</div>
<%
	}
%>
<script type="text/javascript">
var ${id}Selector={};
$(document).ready(function(){
${id}Selector = isperp.createTreeSelector({
		id:"${id}",	tree:${id}Tree,	treeUrl:"${url}",parentIdControlId:"${parentIdControlId}",parentIdDesc:"${parentIdDesc}",autocompleteUrl:"${autocompleteUrl}",	valueControlId:"${valueControlId}",
		displayControlId:"${id}",valueColumn:"${valueColumn}",displayColumn:"${displayColumnName}",onlySelectLeaf:${onlySelectLeaf},
		afterSelected:function (ids,names,treeNode){${afterSelected}},
		afterSelectEmpty:function(){${afterSelectEmpty}}
	});
});
</script>